package com.xaicode.learn.java.multithreadarch.ch2;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Locker cjxia@isoftstone.com
 * @version 1.0
 */
public class ThreadCounter extends Thread {

    final static AtomicInteger counter = new AtomicInteger(0);

    public static void main(String[] args) {
        try {
            while (true) {
                new ThreadCounter().start();
            }
        } catch (Throwable throwable) {
            System.out.println("failed at => " + counter.get());
        }
    }

    @Override
    public void run() {
        try {
            System.out.printf("The %d thread be created", counter.getAndIncrement());
            TimeUnit.MINUTES.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
